package com.ytjj.qmyx.admin.eunm;

import com.ytjj.qmyx.admin.fun.TimeInterfaceFun;
import com.ytjj.qmyx.admin.model.dto.TimeDto;
import com.ytjj.qmyx.admin.utils.CalendarUtil;
import lombok.Getter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Getter
public enum TimeEnums {

    /**
     * 时间搜索条件
     */
    TIME(dayTime -> {
        LocalDate baseTime = LocalDate.parse((String) dayTime, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        Date startTime = CalendarUtil.dateFormatParse(baseTime);
        Date endTime = CalendarUtil.getEndTime(startTime);
        return new TimeDto(startTime, endTime);
    }),

    /**
     * 日搜索条件
     */
    DAY(dayTime -> {
        LocalDate today = LocalDate.now();
        Date startTime = CalendarUtil.dateFormatParse(today);
        Date endTime = CalendarUtil.getEndTime(startTime);
        return new TimeDto(startTime, endTime);
    }),
    /**
     * 周搜索条件
     */
    WEEK(dayTime -> {
        LocalDate today = LocalDate.now();
        LocalDate weekDay = LocalDate.now().minusDays(DateTypeEnums.WEEK.getDayNum());
        Date startTime = CalendarUtil.dateFormatParse(weekDay);
        Date endTime = CalendarUtil.dateFormatParse(today);
        return new TimeDto(startTime, endTime, weekDay);
    }),
    /**
     * 月搜索条件
     */
    MONTH(dayTime -> {
        LocalDate today = LocalDate.now();
        LocalDate monthDay = LocalDate.now().minusDays(DateTypeEnums.MONTH.getDayNum());
        Date startTime = CalendarUtil.dateFormatParse(monthDay);
        Date endTime = CalendarUtil.dateFormatParse(today);
        return new TimeDto(startTime, endTime, monthDay);
    });

    TimeInterfaceFun timeInterfaceFun;

    TimeEnums(TimeInterfaceFun timeInterfaceFun) {
        this.timeInterfaceFun = timeInterfaceFun;
    }

    public static TimeInterfaceFun getTimeEnums(String time) {
        TimeEnums[] timeEnums = TimeEnums.values();
        for (TimeEnums timeEnums1 : timeEnums) {
            if (timeEnums1.name().equals(time)) {
                return timeEnums1.getTimeInterfaceFun();
            }
        }
        return null;
    }


}
